import java.util.ArrayList;
import java.util.Set;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 强仔
 * Date: 2021-11-08
 * Time: 20:52
 */
public class TestDemo {

    //字符串分割
    public boolean wordBreak(String s, Set<String> dict) {
        boolean[] canBreak = new boolean[s.length()+1];
        canBreak[0] = true;
        for (int i = 1; i < canBreak.length; i++) {
            int j = 0;
            for (; j < i; j++) {
                if(canBreak[j] && dict.contains(s.substring(j,i))){
                    canBreak[i] = true;
                    break;
                }
            }
            if(j == i){
                canBreak[i] = false;
            }
        }
        return canBreak[s.length()];
    }
}
